<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>深拷贝方法一</title>
  </head>
  <body>
    <script>
      const obj = {
        uname: "pink",
        age: 18,
        hobby: ["乒乓球", "足球", "羽毛球"],
        family: {
          baby: "luochen",
        },
      };
      const o = {};
      // 拷贝函数
      function deepCopy(newObj, oldObj) {
        for (let k in oldObj) {
          if (oldObj[k] instanceof Array) { //  typeof []   ---> Object
            newObj[k] = [];
            deepCopy(newObj[k], oldObj[k]);
          } else if (oldObj[k] instanceof Object) {
            newObj[k] = {};
            deepCopy(newObj[k], oldObj[k]);
          } else {
            newObj[k] = oldObj[k];
          }
        }
      }
      // 函数调用有两个参数
      deepCopy(o, obj);
      const a = ['abc', 'efg']

      // for(let k in a) {
      //   console.log('🚀 ~ This is a result of console.log ~ ✨: ', k, a[k]);
      // }

      console.log('🚀 ~ This is a result of console.log ~ ✨: ==', o.a === obj.a);
      console.log("o",o);
      console.log(obj);
    //  ☆ 注意：一定要将判断数组的写在前面，因为数组也会判断成对象类型
    </script>
  </body>
</html>
